package org.community.controller;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.spring.SpringMVCUtil;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaFoxUtil;
import lombok.Data;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.Resource;

@Controller
@Data
public class PageController {


    @Resource
    private UserInfoController infoController;

    //个人资料
    @GetMapping("/community/personal")
    public String toPersonMain(){
        return "personal-main";
    }

    //账号安全
    @GetMapping("/community/personal/security")
    public String toSecurity(){
        return "personal-main-security";
    }

    //个人空间
    @GetMapping(value={"/community/personal/space","/"})
    public String toPersonalSpace(){
        return "redirect:/community/personal/space/"+ StpUtil.getLoginId();
    }

    //个人空间
    @GetMapping(value={"/community/personal/space/{ownerId}"})
    public String toPersonalSpace(@PathVariable("ownerId") Integer ownerId, Model model){
        if(!this.getInfoController().getUserInfoService().userInfoInitAndCheck(ownerId)){
            return "redirect:/community/personal/space";
        }
        model.addAttribute("ownerId",ownerId);
        return "personal-space";

    }


    //个人空间-留言板
    @GetMapping("/community/personal/space/message")
    public String toPersonalSpaceMessage(){
        return "personal-space-message";
    }

    //私人空间
    @GetMapping("/community/personal/private_spaces")
    public String toPrivateSpaces(){
        return "personal-main-private-spaces";
    }

    //返回登录界面
    @GetMapping("/login")
    public String toLogin(){
        System.out.println("执行有关方法");
        return "redirect:/";
    }

}
